<template>
  <div class="app-container">
    <el-card class="search-card">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="学院" prop="depId">
            <el-select v-model="queryParams.depId" @change="depChange" placeholder="请选择学院" clearable>
              <el-option
                v-for="item in departmentList"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="专业" prop="subjectId">
            <el-select v-model="queryParams.subjectId" placeholder="请选择专业" clearable>
              <el-option
                v-for="item in subjectList"
                :key="item.id"
                :label="item.subjectName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="学号" prop="studentNum">
            <el-input
              v-model="queryParams.studentNum"
              placeholder="请输入学号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="姓名" prop="studentName">
            <el-input
              v-model="queryParams.studentName"
              placeholder="请输入姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="民族" prop="nation">
            <el-select v-model="queryParams.nation" placeholder="请选择民族" clearable>
              <el-option
                v-for="dict in dict.type.nation"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="政治面貌" prop="politicsStatus">
            <el-select v-model="queryParams.politicsStatus" placeholder="请选择政治面貌" clearable>
              <el-option
                v-for="dict in dict.type.politics_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="身份证号" prop="idCard">
            <el-input
              v-model="queryParams.idCard"
              placeholder="请输入身份证号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="在校状态" prop="stateSchool">
            <el-select v-model="queryParams.stateSchool" placeholder="请选择在校状态" clearable>
              <el-option
                v-for="dict in dict.type.state_school"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="年级" prop="grade">
            <el-input
              v-model="queryParams.grade"
              placeholder="请输入年级"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="学制" prop="educationalSystem">
            <el-select v-model="queryParams.educationalSystem" placeholder="请选择学制" clearable>
              <el-option
                v-for="dict in dict.type.educational_system"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
    </el-card>

    <el-card class="table-card">
        <el-row :gutter="10" class="mb8">
<!--          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['dews:info:export']"
            >导出</el-button>
          </el-col>-->
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" align="center" prop="id" />
          <el-table-column label="院系" align="center" prop="depName" />
          <el-table-column label="专业" align="center" prop="subjectName" />
          <el-table-column label="学号" align="center" prop="studentNum" />
          <el-table-column label="姓名" align="center" prop="studentName" />
          <el-table-column label="出生日期" align="center" prop="birth" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.birth, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="民族" align="center" prop="nation">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.nation" :value="scope.row.nation"/>
            </template>
          </el-table-column>
          <el-table-column label="政治面貌" align="center" prop="politicsStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.politics_status" :value="scope.row.politicsStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="入学时间" align="center" prop="enterTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.enterTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="毕业时间" align="center" prop="graduateTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.graduateTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="身份证号" align="center" prop="idCard" />
          <el-table-column label="在校状态" align="center" prop="stateSchool">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.state_school" :value="scope.row.stateSchool"/>
            </template>
          </el-table-column>
          <el-table-column label="年级" align="center" prop="grade" />
          <el-table-column label="班级" align="center" prop="clazzName" />
          <el-table-column label="学制" align="center" prop="educationalSystem">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.educational_system" :value="scope.row.educationalSystem"/>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" />

        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    </el-card>
   </div>
</template>

<script>
import { listInfo } from "@/api/information/studentInfo";
import { getCollege } from '@/api/system/dept'
import { getSubjectByCollegeId } from '@/api/information/subject'

export default {
  name: "Info",
  dicts: ['educational_system', 'state_school', 'nation', 'politics_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生信息详情表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        depId: null,
        subjectId: null,
        studentNum: null,
        studentName: null,
        birth: null,
        nation: null,
        politicsStatus: null,
        enterTime: null,
        graduateTime: null,
        idCard: null,
        stateSchool: null,
        grade: null,
        clazzId: null,
        educationalSystem: null
      },
      departmentList: [],
      subjectList: [],
    };
  },
  created() {
    this.getList();
    this.findCollege()
    this.findSubjectByCollegeId({depId: null})
  },
  methods: {
    findCollege(){
      getCollege().then(res => {
        this.departmentList = res.data
      })
    },
    depChange(val){
      this.findSubjectByCollegeId({depId: val})
    },
    // 根据学院ID查询专业信息
    findSubjectByCollegeId(data) {
      getSubjectByCollegeId(data).then(res =>{
        this.subjectList = res.data
      })
    },
    /** 查询学生信息详情列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        depId: null,
        subjectId: null,
        studentNum: null,
        studentName: null,
        birth: null,
        nation: null,
        politicsStatus: null,
        enterTime: null,
        graduateTime: null,
        idCard: null,
        stateSchool: null,
        grade: null,
        clazzId: null,
        educationalSystem: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
